package com.example.controller;

import com.example.pojo.Dev;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.R;
import com.example.handler.InServerHandler;

import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class clientList {
	@GetMapping("/clientlist")//打印所有已连接的网关
	@ResponseBody
	public R cilentlist() {
		//System.err.println(InServerHandler.channelGroup);
         List<Map> list  =new  ArrayList<>();
       // Map<String, SocketAddress> map=new HashMap<>();
        final int[] i = new int[1];
         i[0] =0;
		InServerHandler.channelGroup.forEach(ch->{
		   // System.err.println("id: "+ch.id());
            Map<String, SocketAddress> map=new HashMap<>();
            map.put("address",ch.remoteAddress());
			list.add(i[0],map);
            i[0]++;
		});
		return  R.ok().put("list",list).put("size", InServerHandler.channelGroup.size());
       }
}
